package com.example.userservice.util;

import com.google.common.base.Throwables;
import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

/**
 * @author ：Anitaxiaofeng
 * @description：
 * @create 2018-05-27
 **/
public class HashUtils {

//    private static final String salt = "mooc&comsuid&";
//
//    public static String getMD5(String passwd) {
//        String base = passwd + "/" + salt;
//        String md5 = DigestUtils.md5DigestAsHex(base.getBytes());
//        return md5;
//    }



    private static final HashFunction FUNCTION = Hashing.md5();

    private static final String SALT = "mooc.com";

    private static final HashFunction MURMUR_FUNC = Hashing.murmur3_128();

    public static String encryPassword(String password) {
        HashCode hashCode = FUNCTION.hashString(password+SALT, Charset.forName("UTF-8"));
        return hashCode.toString();
    }


    public static String hashString(String input) {
        HashCode code = null;
        try {
            code = MURMUR_FUNC.hashBytes(input.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            Throwables.propagate(e);
        }
        return code.toString();
    }

}

